<html><head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8">
    <title>测试注册</title>
    <link rel="stylesheet" media="screen" href="dist/css/login.css">
</head>
<body>
<!-- particles.js container -->
<div id="particles-js" style="display: flex;align-items: center;justify-content: center">

    <canvas class="particles-js-canvas-el" width="1920" height="548" style="width: 100%; height: 100%;"></canvas></div>
<div class="apTitle"> 注册</div>
<div class="logcon"><input name="username" type="text" placeholder="账号">
    <input name="password" type="password" placeholder="密码">
    <button type="button" onclick="register()">注册</button></div>


<!-- scripts -->
<script src="dist/js/login.js"></script>
<script src="dist/js/loginApp.js"></script>
<script src="plugins/jquery/jquery.min.js"></script>
<script src="dist/js/md5.js"></script>
<script src="dist/js/common.js"></script>
<script src="dist/js/util.js"></script>
<script>
    function register(){
        $.ajax({
            type: "post",
            url: "http://127.0.0.1:7001/api/ws/register",
            dataType: "json",
            data: {"username":$("input[name='username']").val(),"password":$("input[name='password']").val()},
            // xhrFields:{
            //     withCredentials:true
            // },
            //crossDomain:true,// 这两个参数要在后端需要设置withCredentials，跨域要指定域名，withCredentials:true
            beforeSend: function(xhr) {
                var timestamp = Date.parse(new Date())/1000;
                var jsonStr ={"appkey":"sys-server","ts":timestamp,"username":$("input[name='username']").val(),"password":$("input[name='password']").val()};
                sign = createSign(jsonStr);
                xhr.setRequestHeader("appkey", appkey);
                xhr.setRequestHeader("ts", timestamp);
                xhr.setRequestHeader("sign", sign);

            },
            error: function (e) {
                alert("错误");

            },
            success: function (res) {
                if(res.code==200 ){
                    alert("注册成功");

                    window.location.href="login.html";
                    return;
                }else{
                    alert(res.msg);
                }

            }
        });
    }
</script>
</body>
</html>